/***************************************************************************
 *   Copyright (C) 2006 by Matej Svejda                                    *
 *   mata@aw-modell.at                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "bpmslider.h"
#include "bpmslider.moc"

#include "bpmedit.h"

BPMSlider::BPMSlider(QWidget *parent, const char *name)
	: QWidget(parent, name)
{
	
	slider = new QSlider(Qt::Horizontal, this);
	slider->setTickInterval(10);
	slider->setTickmarks(QSlider::Below);
	
	bpmEdit = new BPMEdit(this);
	bpmEdit->setMaxLength(3);
	
	connect(slider, SIGNAL(valueChanged(int)), this, SLOT(setBPMEdit(int)));
	connect(bpmEdit, SIGNAL(bpmChanged(int)), this, SLOT(setBPMSlider(int)));
	
	connect(bpmEdit, SIGNAL(clicked()), this, SIGNAL(bpmEditClicked()));
	connect(bpmEdit, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
	
	QHBoxLayout *layout = new QHBoxLayout(this);
	layout->addWidget(slider, 10);
	layout->addSpacing(5);
	layout->addWidget(bpmEdit, 1);
}


BPMSlider::~BPMSlider()
{
}

void BPMSlider::setRange(int min, int max)
{
	slider->setRange(min, max);
	bpmEdit->setBPMRange(min, max);
}

void BPMSlider::setBPMEdit(int bpm)
{
	bpmEdit->setBPMSilently(bpm);
	emit bpmChanged(bpm);
}

void BPMSlider::setBPMSlider(int bpm)
{ 
	slider->setValue(bpm);
	//emit bpmChanged(bpm);
}

void BPMSlider::setBPM(int bpm)
{
	slider->setValue(bpm);
	QString text;
	text.setNum(bpm);
	bpmEdit->setText(text);
}


